-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce support for 'gpt-4-1106-preview' model and dynamic token limit calculation #437
Conversation
/describe |
PR Analysis
PR Feedback
How to use
|
PR Analysis
PR Feedback
|
pr_agent/algo/utils.py
Outdated
def get_max_tokens(model): | ||
max_tokens_model = MAX_TOKENS[model] | ||
if get_settings().config.max_model_tokens: | ||
if max_tokens_model > get_settings().config.max_model_tokens: | ||
max_tokens_model = get_settings().config.max_model_tokens | ||
# get_logger().debug(f"limiting max tokens to {max_tokens_model}") | ||
return max_tokens_model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Refactor the 'get_max_tokens' function to use a local variable for settings to avoid multiple calls to 'get_settings()' which may be inefficient if it involves I/O operations or complex computations.
def get_max_tokens(model): | |
max_tokens_model = MAX_TOKENS[model] | |
if get_settings().config.max_model_tokens: | |
if max_tokens_model > get_settings().config.max_model_tokens: | |
max_tokens_model = get_settings().config.max_model_tokens | |
# get_logger().debug(f"limiting max tokens to {max_tokens_model}") | |
return max_tokens_model | |
def get_max_tokens(model): | |
settings = get_settings() | |
max_tokens_model = MAX_TOKENS[model] | |
if settings.config.max_model_tokens and max_tokens_model > settings.config.max_model_tokens: | |
max_tokens_model = settings.config.max_model_tokens | |
# get_logger().debug(f"limiting max tokens to {max_tokens_model}") | |
return max_tokens_model |
pr_agent/algo/utils.py
Outdated
def get_max_tokens(model): | ||
max_tokens_model = MAX_TOKENS[model] | ||
if get_settings().config.max_model_tokens: | ||
if max_tokens_model > get_settings().config.max_model_tokens: | ||
max_tokens_model = get_settings().config.max_model_tokens | ||
# get_logger().debug(f"limiting max tokens to {max_tokens_model}") | ||
return max_tokens_model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Add a guard clause to 'get_max_tokens' to handle the case where the model is not found in the MAX_TOKENS dictionary, which would currently raise a KeyError.
def get_max_tokens(model): | |
max_tokens_model = MAX_TOKENS[model] | |
if get_settings().config.max_model_tokens: | |
if max_tokens_model > get_settings().config.max_model_tokens: | |
max_tokens_model = get_settings().config.max_model_tokens | |
# get_logger().debug(f"limiting max tokens to {max_tokens_model}") | |
return max_tokens_model | |
def get_max_tokens(model): | |
if model not in MAX_TOKENS: | |
raise ValueError(f"Model '{model}' not found in MAX_TOKENS dictionary.") | |
max_tokens_model = MAX_TOKENS[model] | |
settings = get_settings() | |
if settings.config.max_model_tokens and max_tokens_model > settings.config.max_model_tokens: | |
max_tokens_model = settings.config.max_model_tokens | |
# get_logger().debug(f"limiting max tokens to {max_tokens_model}") | |
return max_tokens_model |
pr_agent/settings/configuration.toml
Outdated
@@ -10,6 +10,7 @@ use_repo_settings_file=true | |||
ai_timeout=180 | |||
max_description_tokens = 500 | |||
max_commits_tokens = 500 | |||
max_model_tokens = 32000 # even if a model supports more tokens, quality may degrade. Hence, enable to limit the number of tokens. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The 'max_model_tokens' setting should be documented to explain its purpose and effect on the system, especially since it overrides the model's default token limit.
max_model_tokens = 32000 # even if a model supports more tokens, quality may degrade. Hence, enable to limit the number of tokens. | |
# Limits the maximum number of tokens that can be used by any model, regardless of the model's default capabilities. | |
# This can be useful to ensure consistent performance and to prevent issues related to large token counts. | |
max_model_tokens = 32000 |
pr_agent/algo/utils.py
Outdated
if max_tokens_model > get_settings().config.max_model_tokens: | ||
max_tokens_model = get_settings().config.max_model_tokens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, Use the min
function:
max_tokens_model = min(max_tokens_model, get_settings().config.max_model_tokens)
Incremental PR Review
PR Analysis
PR Feedback
|
Introduce support for 'gpt-4-1106-preview' model and dynamic token limit calculation
PR Type:
Enhancement
PR Description:
get_max_tokens
to dynamically calculate the maximum number of tokens based on model capabilities and configuration limits.get_max_tokens
function instead of the staticMAX_TOKENS
dictionary.configuration.toml
to include a newmax_model_tokens
setting to allow limiting the number of tokens used, regardless of the model's maximum.PR Main Files Walkthrough:
files:
pr_agent/algo/__init__.py
: Added 'gpt-4-1106-preview' model with a token limit of 128,000 to the MAX_TOKENS dictionary.pr_agent/algo/utils.py
: Introduced theget_max_tokens
function that returns the maximum number of tokens for a given model, considering themax_model_tokens
setting from the configuration.pr_agent/algo/pr_processing.py
: Replaced staticMAX_TOKENS
dictionary usage with theget_max_tokens
function to dynamically calculate token limits during PR processing.pr_agent/tools/pr_similar_issue.py
: Updated to useget_max_tokens
instead ofMAX_TOKENS
for token count checks when processing issues.pr_agent/settings/configuration.toml
: Added a newmax_model_tokens
setting to allow configuration of a maximum token limit for models.